package com.software.seakdream.service;

import com.software.seakdream.entity.Integral;
import com.software.seakdream.entity.UserInfo;
import com.software.seakdream.repository.IntegralRepository;
import com.software.seakdream.repository.UserInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//积分界面Service
@Service
public class IntegralServiceImpl implements IntegralService {

    @Autowired
    private IntegralRepository integralRepository;
    @Autowired
    private UserInfoRepository userInfoRepository;


    //查找所有的积粉分任务项
    @Override
    public List<Integral> findAllIntegral(){
        List<Integral> lists = integralRepository.findAllIntegral();
        return lists;
    }

    //完成任务时给加积分
    @Override
    public void addPointsWhenFinish() {

    }

    @Override
    public void updateIntegral(Integral integral) {
        integralRepository.updateIntegral(integral);
    }


    //通过UserInfo的id获取user的总积分
    @Override
    public Integer findUserPointById(String userId) {
        UserInfo userInfo = userInfoRepository.getUserInfo(userId);
        return userInfo.getPoints();
    }

    //通过积分类id获取积分数值
    @Override
    public Integer findBonusByIntegralId(Integer integralId) {
        Integer bonus = integralRepository.findBonusByIntegralId(integralId);
        return bonus;
    }
}
